package com.dgut.configuration;

import com.dgut.Service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.IOException;

@Configuration
@EnableScheduling
public class MyScheduleTask {
    private DataService service;

    @Autowired
    public void setService(DataService service) {
        this.service = service;
    }

    //每天凌晨0点更新数据
    @Scheduled(cron = "0 0 0 * * *")
    public void fetchCoronaVirusData(){
        try {
            service.getRegionData();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
